#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char* argv[])
{
	printf("enter @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);

	float pf;
	
	void *dp=NULL;
	float (*pgetfloatpoint)(void);
	char * error=NULL;

	printf("d-call libfoo2.so start @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);
	if(!(dp=dlopen("./libfoo2.so", RTLD_LAZY)))
	{
		printf("load libfoo2.so falied at main %d.\n", __LINE__);
		return 1;
	}

	pgetfloatpoint=(float (*) (void) )dlsym(dp, "getfloatpoint");
	error=dlerror();

	if(error)
	{
		printf("dlerror exit at main %d.\n", __LINE__);
		return 1;
	}
	
	pf=pgetfloatpoint();
	printf("@ func:%s , line:%3d , file:%s ,  the init value in libfoo2.so is pf=%4.3f .\n", __FUNCTION__, __LINE__, __FILE__ , pf);

	float setvalue;
	setvalue=10.0f;
	void (*psetfloatpoint)(float);

	psetfloatpoint=(void (*) (float)) dlsym(dp, "setfloatpoint");
	
	char* error22=NULL;
	error22=dlerror();
	if(error22)
	{
		printf("dlerror exit at main %d.\n", __LINE__);
		return 1;
	}

	psetfloatpoint(setvalue);
	printf("@ func:%s , line:%3d , file:%s , the setted value in libfoo2.so is setted to setvalue=%4.3f .\n", __FUNCTION__, __LINE__, __FILE__ , setvalue);

	float doublecheckvalue;
	doublecheckvalue=pgetfloatpoint();
	printf("@ func:%s , line:%3d , file:%s ,  the value in libfoo2.so is doublechecked by doublecheckedvalue=%4.3f .\n", __FUNCTION__, __LINE__, __FILE__ , doublecheckvalue);

	/* dlclose(dp);*/ /* have the output "result.aix.v1.log" */
	printf("d-call libfoo2.so finish @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);

	void *dp2=NULL;
	void (*pcallfoo2)(void);
	char * error2=NULL;

	printf("d-call libfoo1.so start @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);
	if(!(dp2=dlopen("./libfoo1.so", RTLD_LAZY)))
	{
		printf("load libfoo1.so falied at main %d.\n", __LINE__);
		return 1;
	}

	pcallfoo2=(void (*) (void) ) dlsym(dp2, "callfoo2");
	error2=dlerror();

	if(error2)
	{
		printf("dlerror exit at main %d.\n", __LINE__);
		return 1;
	}
	
	pcallfoo2();

	dlclose(dp2);
	dlclose(dp); /* have the output "result.aix.v2.log" */
	printf("d-call libfoo1.so finish @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);

	printf("exit @ func:%s , line:%3d , file:%s .\n",__FUNCTION__, __LINE__, __FILE__);
	return 0;
};

